package cn.edu.fjnu.camera;

import java.util.HashMap;
import java.util.LinkedList;

public class LinkedCacheMap{
	
	LinkedList<String> m_linkedList;
	HashMap<String, Object> m_cache;
	int m_size;
	int m_current_size=0;
	public LinkedCacheMap(int i){
		m_size = i;
		m_linkedList = new LinkedList<String>();
		m_cache = new HashMap<String, Object>(); 
	}
	
	public void add(Object obj, String tag){
		if(has(tag))
			return;
		if(m_current_size<m_size){
			m_cache.put(tag, obj);
			m_linkedList.add(tag);
			m_current_size++;
		}else{
			m_cache.remove(m_linkedList.getFirst());
			m_cache.put(tag, obj);
			m_linkedList.removeFirst();
			m_linkedList.add(tag);						
		}
			
	}
	public boolean has(String tag){
		return m_cache.containsKey(tag);
	}
	
	public Object get(String tag){
		
		return m_cache.get(tag);
	}
}
